package com.tgy.myplus.基础学习.Thread.线程池;

import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.*;

/***
 * @ClassName: Test线程池理解
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 18:16 2022/3/8
 * @version : V1.0
 */
public class Test {
    public static void main(String[] args) {
        ThreadPoolExecutor.CallerRunsPolicy callerRunsPolicy = new ThreadPoolExecutor.CallerRunsPolicy();
        BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(2);
        ThreadPoolExecutor pool = new ThreadPoolExecutor(3, 4, 60, TimeUnit.MICROSECONDS, queue,callerRunsPolicy);

        for (int i = 0; i < 20; i++) {
            pool.execute(() -> {
                System.out.println(Thread.currentThread().getName() + "你好");
                try {
                    TimeUnit.MILLISECONDS.sleep(1200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        }
        pool.shutdown();
    }
}
